import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 数组序号转换
 *
 * @USER: Administrator
 * @DATE: 2024/9/23 下午10:08
 * @VERSION: 1.0.0
 */
public class LC1331 {
    public static void main(String[] args) {
        LC1331 lc1331 = new LC1331();
        System.out.println(Arrays.toString(lc1331.arrayRankTransform(new int[]{37, 12, 28, 9, 100, 56, 80, 5, 12})));
    }

    public int[] arrayRankTransform(int[] arr) {
        int[] tmp = Arrays.copyOfRange(arr, 0, arr.length);
        Arrays.sort(arr);
        int[] result = new int[arr.length];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i : arr) {
            if (!map.containsKey(i)) {
                map.put(i, map.size()+1);
            }
        }

        for (int i = 0; i < result.length; i++) {
            result[i] = map.get(tmp[i]);
        }

        return result;
    }

}
